package com.hwq.work4.controller;

import com.hwq.work4.dao.ArticleDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Author: hwq
 * @Date: 2020/10/26 17:20
 * @Version 1.0
 */
@Controller
public class CurdController {
    @Autowired
    private ArticleDao articleDao;
    @GetMapping("/")
    public String curd(Model model,
                       @RequestParam(value = "page", defaultValue = "0") int page,
                       @RequestParam(value = "limit", defaultValue = "3") int limit){
        PageRequest pageable = PageRequest.of(page, limit, Sort.Direction.DESC, "id");
        model.addAttribute("list",articleDao.findAll(pageable));
        return "/client/index";
    }
}
